import Vue from 'vue';
import VueRouter from 'vue-router';

Vue.use(VueRouter)

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
	return originalPush.call(this, location).catch(err => err)
}


/**
 * 静态路由
 */
export const constantRouterMap = [

	// 重定向，每次访问*都定向到首页
	{
		path: '',
		redirect: '/home',
		hidden: true,
	},
	{
		path: '/home',
		meta: {
			icon: null,
			title: null,
		},
		hidden: true,
		sort: null,
		component: () => import('@/views/home'),
	},
	{
		path: '/video',
		meta: {
			icon: null,
			title: null,
		},
		hidden: true,
		sort: null,
		component: () => import('@/views/video'),
	},

]
/**
 * 动态路由
 */
export const asyncRouterMap = [


]


const router = new VueRouter({
	mode: "history",
	routes: constantRouterMap,
	// // 控制路由跳转滚动条的位置为最顶部
	scrollBehavior(to, from, savedPosition) {
		// 始终滚动到顶部，y代表距离顶部的距离
		return { y: 0 }
	},
})

// const whiteList = ['/login', '/file/share/'] // 不重定向白名单

router.beforeEach((to, from, next) => {
	next()	
})

export default router